package org.windblog.core.servlet.category;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.windblog.core.CategoryService;
import org.windblog.core.entity.Category;




@SuppressWarnings("serial")
public class AddCategoryServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse response)
			throws ServletException, IOException {
		
		
		String name = req.getParameter("name").trim();
		String slug = req.getParameter("slug");
		String description = req.getParameter("description");
		if(name==null || CategoryService.isExist(name))
		{
			response.sendRedirect("/admin/categories.jsp?message=1");
		}else
		{
			Category cat = new Category();
			cat.setName(name);
			cat.setSlug(slug);
			cat.setDescription(description);

			CategoryService.setCategory(cat);
			response.sendRedirect("/admin/categories.jsp?message=2");
		}
	}
	
}
